var designClass = "design_class", hideClass = "hide_class", browseClass = "browse_class", addClass = "add_class", editClass = "edit_class";
var upWindow = window.parent.frames["zwIframe"];
var path = window.location.protocol+"//"+window.location.hostname
//alert(path)
//var path = 'http://10.112.17.150'
if (!upWindow) {
	upWindow = window.parent.frames["componentDiv"].frames["zwIframe"];
}
// 关闭自定义扩张控件弹出窗口
function fy_dialog_close() {
	window.parent.$(".layui-layer-iframe").parent().find(".layui-layer-close").trigger(
			"click");
}

function getUpFields(name) {
	return upWindow.$("[validate*='name:\"" + name + "\"']");
}

function getUpFieldsByFieldval(name) {
	return upWindow.$("[fieldval*='displayName:\"" + name + "\"']");
}
function getUpAccountFieldValue(name) {
	var field = getUpFields(name).eq(0);
	return {
		displayValue : field.is("span") ? field.text() : field.val(),
		value : eval("(" + field.parent("span").attr("fieldVal") + ")").value
	};
}

function getUpFieldValueByName(name, index) {
	return getUpFieldValue(getUpFieldsByFieldval(name).eq(index ? index : 0));
}

function getUpFieldValue(field) {
	var fieldVal = field.attr("fieldVal");
	var editTag = field.hasClass(editClass);
	var browseTag = field.hasClass(browseClass);
	var addTag = field.hasClass(addClass);
	if (fieldVal != null && typeof (fieldVal) != 'undefined') {
		fieldVal = eval("(" + fieldVal + ")");
	} else {
		return null;
	}
	var obj = new Object();
	obj.displayName = fieldVal.displayName;
	obj.name = fieldVal.name;
	var tag = true;
	switch (fieldVal.inputType) {
	case "text":
	case "textarea":

		if (editTag) {
			obj.value = field.find("#" + fieldVal.name).val();
		} else if (browseTag) {
			obj.value = fieldVal.value;
		} else if (addTag) {
			obj.value = field.find("#" + fieldVal.name).val();
		}
		break;
	case "checkbox":
		if (editTag) {
			obj.value = field.find("#" + fieldVal.name).val();
		} else if (browseTag) {
			obj.value = field.find("#" + fieldVal.name).val();
		}
		break;
	case "radio":
		if (editTag) {
			obj.value = field.find(":radio:checked").attr("val4cal");
		} else if (browseTag) {
			obj.value = field.find(":radio:checked").attr("val4cal");
		}
		break;
	case "select":
		if (editTag) {
			obj.value = field.find("#" + fieldVal.name + " option:selected")
					.attr("val4cal");
		} else if (browseTag) {
			obj.value = field.find("#" + fieldVal.name).attr("val4cal");
		}
		break;
	case "date":
		if (editTag) {
			obj.value = field.find("#" + fieldVal.name).val();
			if (obj.value != "") {
				obj.value = obj.value + " 00:00";
			}
		} else if (browseTag) {
			obj.value = fieldVal.value;
		}
		break;
	case "datetime":
		if (editTag) {
			obj.value = field.find("#" + fieldVal.name).val();
		} else if (browseTag) {
			obj.value = fieldVal.value;
		}
		break;
	case "flowdealoption":
		if (editTag) {
			obj.value = fieldVal.value;
		} else if (browseTag) {
			obj.value = fieldVal.value;
		} else if (addTag) {
			obj.value = fieldVal.value;
		}
		break;
	case "lable":
		if (editTag) {
			obj.value = fieldVal.value;
		} else if (browseTag) {
			obj.value = fieldVal.value;
		}
		break;
	case "relationform":
		if (editTag) {
			obj.value = fieldVal.value;
		} else if (browseTag) {
			obj.value = fieldVal.value;
		}
		break;
	case "relation":
		if (editTag || browseTag) {
			obj.value = fieldVal.value;
		}
		break;
	case "project":
		if (editTag) {
			obj.value = field.find("#" + fieldVal.name).val();
		} else if (browseTag) {
			obj.value = fieldVal.value;
		}
		break;
	case "member":
	case "multimember":
	case "account":
	case "multiaccount":
	case "department":
	case "multidepartment":
	case "post":
	case "multipost":
	case "level":
	case "multilevel":
		if (editTag) {
			obj.value = field.find("#" + fieldVal.name + "_txt").val();
		} else if (browseTag) {
			obj.value = field.find("#" + fieldVal.name).text();
		}
		break;
	case "attachment":
	case "image":
	case "document":
		if (editTag || browseTag) {
			var attNames = "";
			var tempField = field.find("#" + fieldVal.name);
			var tempFileId = "";
			if (tempField[0].tagName.toLowerCase() == "input") {
				tempFileId = tempField.val();
			} else if (tempField[0].tagName.toLowerCase() == "span") {
				tempFileId = tempField[0].innerHTML;
			}
			var atts = upWindow.getAttBySubreference(tempFileId);
			for ( var j = 0; j < atts.length; j++) {
				attNames += atts[j].filename + ",";
			}
			if (attNames != "") {
				attNames = attNames.substr(0, attNames.length - 1);
			}
			obj.value = attNames;
		}
		break;
	case "outwrite":
		if (editTag || browseTag) {
			obj.value = fieldVal.value;
		}
		break;
	case "externalwrite-ahead":
		if (editTag || browseTag) {
			obj.value = fieldVal.value;
		}
		break;
	case "exchangetask":
		if (editTag || browseTag) {
			obj.value = fieldVal.value;
		}
		break;
	case "querytask":
		if (editTag || browseTag) {
			obj.value = fieldVal.value;
		}
		break;
	default:
		tag = false;
	}
	if (obj.value != undefined) {
		obj.value = obj.value.replace("\r\n", ";");
		obj.value = obj.value.replace("\n", ";");
	}
	return obj;
}

function setUpFieldValue(name, value) {
	upWindow.$("[fieldval*='displayName:\"" + name + "\"']").find("input").val(
			value);
	upWindow.$("[fieldval*='displayName:\"" + name + "\"']").find("input")
			.trigger("blur");
}

function setUpFieldValue2(field, value, displayValue, index) {

	try {

		var fieldVal = field.attr("fieldVal");
		var editTag = field.hasClass(editClass);
		var addTag = field.hasClass(addClass);
		value = (value);
		displayValue = displayValue ? (displayValue) : displayValue;
		if (fieldVal != null && typeof (fieldVal) != 'undefined') {
			fieldVal = eval("(" + fieldVal + ")");
		} else {
			return null;
		}
		var tag = true;
		switch (fieldVal.inputType) {
		case "text":
		case "textarea":
			if (editTag) {
				var inField = field.find("#" + fieldVal.name);
				inField.val(value);
				inField.trigger("blur");
			} else if (addTag) {
				var inField = field.find("#" + fieldVal.name);
				inField.val(value);
				inField.trigger("blur");
			}
			break;
		case "checkbox":
			if (editTag) {
				field.find("#" + fieldVal.name).attr("checked", true);
				field.find("#" + fieldVal.name).trigger("click");
			}
			break;
		case "radio":
			if (editTag) {
				field.find(":radio").eq(index).attr("checked", true);
				field.find(":radio").eq(index).trigger("click");
			}
			break;
		case "select":
			if (editTag) {
				var options = field.find("#" + fieldVal.name + " option");
				for ( var k = 0; k < options.length; k++) {
					if (options.eq(k).text() == value)
						options.eq(k).attr("selected", true);
				}
				field.find("#" + fieldVal.name).trigger("change");
			}
			break;
		case "date":
			if (editTag) {
				field.find("#" + fieldVal.name).val(value);
				field.find("#" + fieldVal.name).trigger("blur");
			}
			break;
		case "datetime":
			if (editTag) {
				field.find("#" + fieldVal.name).val(value);
				field.find("#" + fieldVal.name).trigger("blur");
			}
			break;
		case "member":
		case "multimember":
		case "account":
		case "multiaccount":
		case "department":
		case "multidepartment":
		case "post":
		case "multipost":
		case "level":
		case "multilevel":
			if (editTag) {
				field.find("#" + fieldVal.name).val(value);
			}
			break;
		}
	} catch (e) {
		// TODO: handle exception
	}
}
// 添加或者删除行
function addOrDelRepeat(name, newLength) {
	var fields = getUpFieldsByFieldval(name);
	var oldLength = fields.length;
	var tbody = getUpFieldsByFieldval(name).eq(0).parent();
	while (!tbody.is("tbody")) {
		tbody = tbody.parent();
	}
	if (newLength == 0) {
		upWindow.fy_addEmpty(tbody.children().last());
		upWindow.fy_delCurrentRepeat(tbody.children().first());
	} else
		for ( var i = 0, length = Math.abs(newLength - oldLength); i < length; i++) {
			if (newLength > oldLength) {
				upWindow.fy_addEmpty(tbody.children().last());
			} else {
				upWindow.fy_delCurrentRepeat(tbody.children().last());
			}
		}
}
var educationalBackgroundMap = {
	"E01" : "小学",
	"E02" : "初中",
	"E04" : "中专/中技",
	"E03" : "高中",
	"E05" : "大专",
	"E06" : "大专结业",
	"E07" : "本科",
	"E08" : "本科结业",
	"E11" : "博士研究生",
	"E09" : "硕士研究生",
	"E10" : "研究生结业"
};
function getParentTR(dom) {
	if (dom) {
		if (dom.tagName.toLowerCase() == 'tr') {
			return dom;
		} else {
			return getParentTR(dom.parentNode);
		}
	} else {
		return null;
	}
}

function writeRepeatTable() {
	// try {
	// var oldLength = $2("原福耀工作履历_起始日期").length;
	var newLength = lvliJSON.length;

	// for (var i = 0; i < newLength; i++) {
	// getParentTR($2("原福耀工作履历_起始日期")[oldLength - 1]).id = "oper";
	// window.dialogArguments.addEmpty();
	// }
	// for (var i = 0; i < oldLength; i++) {
	// getParentTR($2("原福耀工作履历_起始日期")[0]).id = "oper";
	// window.dialogArguments.del();
	// }
	addOrDelRepeat("原福耀工作履历_起始日期", newLength);

	for ( var i = 0; i < newLength; i++) {
		for ( var key in lvliJSON[i]) {
			try {
				setUpFieldValue2(getUpFieldsByFieldval("原福耀工作履历_" + key).eq(i),
						lvliJSON[i][key] ? lvliJSON[i][key] : "");
			} catch (e) {
			}
		}
	}
	// } catch (e) {
	// alert("填写履历发生异常");
	// }
}

var numberStr = '1234567890.';

var autoWrite = false;

var newPostRankMap;

var oldParentDepPostRankMap;

var oldChildDepPostRankMap;

var oldParentDepPosts;

var lvliJSON;

var changeStatusFields = [ 'memberName', 'lastJoinDate', 'lastLeaveDate',
		'workYear', 'educationalBackground', 'address', 'birthdate' ];

var fieldMap = {
	textField : {
		'memberName' : '复职人员姓名_',
		'memberCode' : '人员编码_',
		'lastJoinDate' : '首次进入福耀日期',
		'lastLeaveDate' : '离职日期',
		'workYear' : '工作年限',
		'educationalBackground' : '原聘用学历_',
		'address' : '籍贯_',
		'birthdate' : '出生日期',
        'newRank' : '复职_职级_',
        'oldRank' : '原单位_职级_'
	},
	select : {
		'oldCompany' : '原单位_制造部',
		'oldDep' : '原单位_部门工厂',
		'oldChildDep' : '原单位_车间科室',
		'oldPost' : '原单位_岗位',
		'newPost' : '复职_岗位_',
        'newCompany' : '复职_制造部_',
        'newDep' : '复职_部门工厂_',
        'newChildDep' : '复职_车间科室_'
	},
	notAllowBlank : {
		'memberName' : '复职人员姓名',
		'memberCode' : '人员编码',
		'lastJoinDate' : '首次进入福耀日期',
		'lastLeaveDate' : '离职日期',
		'educationalBackground' : '原聘用学历',
		'address' : '籍贯',
		'workYear' : '离职日期',
		'birthdate' : '出生日期',
		'newCompany' : '复职制造部',
		'newDep' : '复职部门/工厂',
		'oldCompany' : '原制造部',
		'oldDep' : '原部门/工厂',
		'oldPost' : '原岗位',
		'newPost' : '复职岗位'
	}
};

var oldPostSelectIDArray = [ 'oldCompany', 'oldDep', 'oldChildDep', 'oldPost' ];

function $(id) {
	return document.getElementById(id);
}

function clearAll() {
	for ( var i = 0; i < changeStatusFields.length; i++) {
		$(changeStatusFields[i]).value = '';
		//$(changeStatusFields[i]).readOnly = true;
		//$(changeStatusFields[i]).className = 'readonly';
	}
	for ( var i = 0; i < oldPostSelectIDArray.length; i++) {
		addOption($(oldPostSelectIDArray[i]), [], true, '请选择');
		$(oldPostSelectIDArray[i]).value = '';
		$(oldPostSelectIDArray[i]).disabled = true;
	}

	addOption($('newPost'), [], true, '请选择');
	$('newPost').value = '';
	$('newPost').disabled = true;
	$('newRank').value = '';
	$('oldRank').value = '';
	autoWrite = false;
}

function getRankMap(posts) {
	var map = {};
	if (posts) {
		for ( var i = 0; i < posts.length; i++) {
			map[posts[i].id] = posts[i].rank;
		}
	}
	return map;
}

/**
 * 更改填写界面状态
 */
function changeBaseInfoFieldStatus() {
	console.log(autoWrite);
	if (!autoWrite
			&& document.getElementsByName("joinTimeRadio")[1].checked == true) {
		for ( var i in changeStatusFields) {
			$(changeStatusFields[i]).readOnly = false;
			$(changeStatusFields[i]).className = 'fill';
		}

		$('newPost').disabled = false;
		$('oldCompany').disabled = false;
	} else {
		for ( var i in changeStatusFields) {
			//$(changeStatusFields[i]).readOnly = true;
			//$(changeStatusFields[i]).className = 'readonly';
			if (!autoWrite)
				$(changeStatusFields[i]).value = "";
		}
	}

	if (!autoWrite
			&& document.getElementsByName("joinTimeRadio")[0].checked == true) {
		$('oldCompany').value = '';
		$('oldCompany').disabled = true;

		for ( var i = 0; i < oldPostSelectIDArray.length; i++) {
			if (oldPostSelectIDArray[i] != 'oldCompany') {
				addOption($(oldPostSelectIDArray[i]), [], true, '请选择');
				$(oldPostSelectIDArray[i]).value = '';
				$(oldPostSelectIDArray[i]).disabled = true;
			}
		}
		$('newPost').disabled = true;
		$('oldRank').value = '';
	}
}

/**
 * 删除所有下拉列表选项
 * 
 * @param {}
 *            selectField
 */
function removeAllOption(selectField) {
	var length = selectField.options.length;
	for ( var i = 0; i < length; i++) {
		selectField.options.remove(length - i - 1);
	}
}

function createOption(msg,key){
	var op = document.createElement("option");
	op.value = key;
	op.text = msg;
	return op;
}

/**
 * 
 * @param select
 *            selectField
 * @param array
 *            options
 * @param boolean
 *            blank 是否允许为空
 */
function addOption(selectField, options, blank, msg) {
	selectField.disabled = false;
	removeAllOption(selectField);
	if (options && options.length > 0) {
		if (blank) {
			var blankOption = createOption(msg, '');
			blankOption.style.color = '#777';
			selectField.options.add(blankOption);
			selectField.options[0].selected = true;
		}
		for ( var i = 0; i < options.length; i++) {
			selectField.options.add(createOption(options[i].name, options[i].id));
		}
	}

	if (!autoWrite
			&& document.getElementsByName("joinTimeRadio")[1].checked == true
			&& selectField.id == 'oldPost') {
		selectField.options.add(createOption('其他', 'otherPost'));
	}
}
function insertCorp(){
	//console.info("corpMap1.length = "+corpMap1["key_1028"][1])
	var arr = [];
	var i = 0;
    for(x in corpMap1){
        arr.push({"name":corpMap1[x][1],"id":i})
		i++;
    	//console.info(corpMap1[x][1])
        //$("newCompany").append("<option value='"+corpMap1[x][1]+"'>"+corpMap1[x][1]+"</option>");
    }
    console.info(arr)
    addOption($("newCompany"), arr, true, '请选择');
}

/**
 * 设置单一的选项
 * 
 * @param {}
 *            selectField
 * @param {}
 *            optionBean
 */
function addSingleOption(selectField, optionBean) {
	selectField.disabled = false;
	removeAllOption(selectField);
	if (optionBean) {
		selectField.options.add(createOption(optionBean.name, optionBean.id));
		selectField.options[0].selected = true;
	}
}

function _ajax(params, operate) {
	var xmlhttp = null;
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera,
		xmlhttp = new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	$("lodingDiv").style.display = '';
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
				text = xmlhttp.responseText;

				var result = eval("(" + text + ")");

				if (result.success) {
					operate(result);
				} else {
					alert(result.error);
				}

			} else {
				alert("连接服务器异常");
			}
			$("lodingDiv").style.display = 'none';
		}
	};
	xmlhttp.open("get",
			"../../../oa2hrController.do?method=queryReinstatementInfo&"
					+ params + "&temp=" + Math.random(), true);
	xmlhttp.send();
}

function _ajaxPost(params,url) {
    var xmlhttp = null;
    var result = null;
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera,
        xmlhttp = new XMLHttpRequest();
    } else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
                text = xmlhttp.responseText;

                result = eval("(" + text + ")");
            } else {
                alert("连接服务器异常");
            }
        }
    };
    xmlhttp.open("post",url, false);
    xmlhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    xmlhttp.send(params);
    return result;
}
function getToken(_params,_url){
     return _ajaxPost(_params,_url).id
}
function getCorp(_params,_url){
    return _ajaxPost(_params,_url).message;
}

window.onload = function() {

	$('queryMemberCode').focus();

	// 学历选择
	$("educationalBackground").onclick = function() {
		if (!autoWrite
				&& document.getElementsByName("joinTimeRadio")[1].checked == true) {
			addMySelectPlugin(educationalBackgroundMap, document
					.getElementById("educationalBackground"));
		}
	};

	// 进入福耀时间2011年前或者后时间触发
	document.getElementsByName("joinTimeRadio")[0].onclick = document
			.getElementsByName("joinTimeRadio")[1].onclick = changeBaseInfoFieldStatus;
	// 日期选择
	$("birthdate").onfocus = $("lastJoinDate").onfocus = $("lastLeaveDate").onfocus = function() {
		if (!autoWrite
				&& document.getElementsByName("joinTimeRadio")[1].checked == true) {
			WdatePicker({
				readOnly : true
			});
		}
	};

	$("lastLeaveDate").onchange = $("lastJoinDate").onchange = function() {
		if ($("lastLeaveDate").value != '' || $("lastJoinDate").value != '') {
			var lastLeaveDate = new Date($("lastLeaveDate").value.replace(/-/g,
					'/'));
			var lastJoinDate = new Date($("lastJoinDate").value.replace(/-/g,
					'/'));
			if (lastJoinDate > lastLeaveDate) {
				alert('离职日期不能比首次进入福耀日期早');
				this.value = '';
			}
		}
	};

	$('workYear').onchange = function() {
		if (this.value != '') {
			if (isNaN(this.value)) {
				alert('工作年限必须是数字');
				this.value = '';
			} else {
				if (this.value.indexOf('.') != -1) {
					this.value = this.value.substr(0,
							(this.value.indexOf('.') + 3));
				}
			}
		}
	};

	// 新岗位选择
	$('newPost').onchange = function() {
		if (this.options[0].value == '') {
			this.options.remove(0);
		}
		$('newRank').value = newPostRankMap[this.value] ? newPostRankMap[this.value]
				: '';
	};

    $('newCompany').onchange = function() {
    	console.log(this.value)
        addOption($('newDep'), getCorp(JSON.stringify({pk_corp:this.value}),path+"/seeyon/rest/corp/getDept?token="+token), true,'请选择');
	}
	$('newDep').onchange = function() {
        // if(getCorp(JSON.stringify({pk_deptdoc:this.value}),path+"/seeyon/rest/corp/getChildDept?token="+token).length>0){
         //    addOption($('newChildDep'), getCorp(JSON.stringify({pk_deptdoc:this.value}),path+"/seeyon/rest/corp/getChildDept?token="+token), true,'请选择');
		// }else{
         //    addOption($('newPost'), getCorp(JSON.stringify({pk_deptdoc:this.value}),path+"/seeyon/rest/corp/getPost?token="+token), true,'请选择');
		// }
        addOption($('newChildDep'), getCorp(JSON.stringify({pk_deptdoc:this.value}),path+"/seeyon/rest/corp/getChildDept?token="+token), true,'请选择');
        addOption($('newPost'), getCorp(JSON.stringify({pk_deptdoc:this.value}),path+"/seeyon/rest/corp/getPost?token="+token), true,'请选择');

	}
    $('newChildDep').onchange = function(){
        addOption($('newPost'), getCorp(JSON.stringify({pk_deptdoc:this.value}),path+"/seeyon/rest/corp/getPost?token="+token), true,'请选择');
	}

	// 原单位信息选择
	$('oldPost').onchange = $('oldCompany').onchange = $('oldDep').onchange = $('oldChildDep').onchange = function() {
		if (!autoWrite) {
			this.options.selectedIndex = 0;
		} else {
			if (this.id == 'oldCompany') {
				if (this.options[0].value == '') {
					this.options.remove(0);
				}
				_ajax('pk=' + this.value + '&operate=2', function(result) {
					var data = result.data;
					addOption($('oldDep'), data.children, true, '请选择');
				});
			} else if (this.id == 'oldDep') {
				if (this.options[0].value == '') {
					this.options.remove(0);
				}
				_ajax('pk=' + this.value + '&operate=3', function(result) {
					var data = result.data;
					addOption($('oldChildDep'), data.children, true, '');
					addOption($('oldPost'), data.posts, true, '请选择');
					oldParentDepPostRankMap = getRankMap(data.posts);
					oldParentDepPosts = data.posts;
				});
			} else if (this.id == 'oldChildDep') {
				if (this.value == '') {
					addOption($('oldPost'), oldParentDepPosts, true, '请选择');
				} else {
					_ajax('pk=' + this.value + '&operate=4', function(result) {
						var data = result.data;
						addOption($('oldPost'), data.posts, true, '请选择');
						oldChildDepPostRankMap = getRankMap(data.posts);
					});
				}
			} else if (this.id == 'oldPost') {
				if (this.options[0].value == '') {
					this.options.remove(0);
				}
				if ($('oldChildDep').value && $('oldChildDep').value != '') {
					$('oldRank').value = oldChildDepPostRankMap[this.value] ? oldChildDepPostRankMap[this.value]
							: '';
				} else {
					$('oldRank').value = oldParentDepPostRankMap[this.value] ? oldParentDepPostRankMap[this.value]
							: '';
				}
			}
		}
	};

	// 查询人员信息
	$("query").onclick = function() {
		lvliJSON = [];
		var qMemberCode = $("queryMemberCode").value.replace(/ /g, '');
		if (qMemberCode == '') {
			alert('查询工号不能为空格');
			return;
		}
		if (qMemberCode.length != 6 || isNaN(qMemberCode.replace(/0/g, ''))) {
			alert('工号为六位数字');
			return;
		}
		clearAll();
		_ajax(
				'memberCode=' + qMemberCode + '&operate=1',
				function(result) {
					var data = result.data;
					for ( var key in data) {
						if ((typeof data[key]).toLowerCase() == 'string') {

							if (key == "lvliJSON" && data[key]) {
								lvliJSON = eval('(' + data[key] + ')');
							} else if ($(key)) {
								$(key).value = data[key];
							}
						}

					}
					addOption($('newPost'), data.newPosts, true, '请选择');
					newPostRankMap = getRankMap(data.newPosts);
					if (data.exist) {
						autoWrite = true;
						changeBaseInfoFieldStatus();
						for ( var i = 0; i < oldPostSelectIDArray.length; i++) {
							addSingleOption($(oldPostSelectIDArray[i]),
									data[oldPostSelectIDArray[i]]);
						}
						$('oldRank').value = data.oldPost.rank ? data.oldPost.rank
								: '';
					} else {
						$('memberCode').value = data.memberCode;
						autoWrite = false;
						addOption($('oldCompany'), data.companyList, true,
								'请选择');
						$('oldCompany').disabled = true;
						$('newPost').disabled = true;
						changeBaseInfoFieldStatus();
					}
				});
	};
	$('ok_button').onclick = function() {
		for ( var key in fieldMap.notAllowBlank) {
			if ($(key).value == '') {
				alert(fieldMap.notAllowBlank[key] + '不能为空');
				return;
			}
		}
		for ( var key in fieldMap.textField) {
			//console.log($(key).selectedIndex);
			try {
                var index = $(key).selectedIndex
				setUpFieldValue2(getUpFieldsByFieldval(fieldMap.textField[key])
						.eq(0), $(key).value);
			} catch (e) {
			}
		}
		for ( var key in fieldMap.select) {
			if ($(key).options.length > 0) {
				try {
					setUpFieldValue2(
							getUpFieldsByFieldval(fieldMap.select[key]).eq(0),
							$(key).options[$(key).selectedIndex].text);
				} catch (e) {
				}
			}
		}
		writeRepeatTable();
		setUpFieldValue2(getUpFieldsByFieldval('存在复职车间或科室'),
				($('newChildDep').value == '' ? '2' : '1'));
		console.info($('oldCompany').value);
		console.info(corpMap['key_' + $('oldCompany').value]);
		console.info(getUpFieldsByFieldval('原制造部选择').eq(0));
		setUpFieldValue2(getUpFieldsByFieldval('原制造部选择').eq(0), corpMap['key_'
				+ $('oldCompany').value]);
		// updoc.getElementById("原制造部选择").value =
		// $('oldCompany').options[$('oldCompany').selectedIndex].text;
		// ;
		fy_dialog_close();
	};
   // insertCorp();
    var token = getToken(JSON.stringify({userName:"zhang",password:"zhang123"}),path+"/seeyon/rest/token");
	//console.info(token)
	//console.log(getCorp(JSON.stringify({}),"http://10.112.17.150/seeyon/rest/corp/getCorp?token="+token))
    //console.log(getCorp({pk_corp:"1002"},"http://10.112.17.150/seeyon/rest/corp/pk_deptdoc?token="+token))
     addOption($('newCompany'), getCorp(JSON.stringify({}),path+"/seeyon/rest/corp/getCorp?token="+token), true,'请选择');

};